 package synchronized锁重入;



class serviceOne{
	synchronized public void testMethod()
	{
		if(Thread.currentThread().getName().equals("a"))
		{
			System.out.println("ThreadName="+Thread.currentThread().getName()+" run beginTime="
					+System.currentTimeMillis());
			int i=1;
			while(i==1)
			{
				if((""+Math.random()).substring(0, 8).equals("0.123456"))
				{
					System.out.println("ThreadName="+Thread.currentThread().getName()+" run exceptionTime="
							+System.currentTimeMillis());
					Integer.parseInt("a");
				}
			}
		}
		else {
			System.out.println("Thread B run Time="+System.currentTimeMillis());
		}
	}
}
class ThreadA extends Thread{
	private serviceOne service;
	public ThreadA( serviceOne service)
	{
		super();
		this.service=service;
		
	}
	public void run()
	{
		service.testMethod();
	}
}
class ThreadB extends Thread{
	private serviceOne service;
	public ThreadB( serviceOne service)
	{
		super();
		this.service=service;
		
	}
	public void run()
	{
		service.testMethod();
	}
}
public class Test2_16 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			serviceOne service=new serviceOne();
			ThreadA a=new ThreadA(service);
			a.setName("a");
			a.start();
			Thread.sleep(500);
			ThreadB b=new ThreadB(service);
			b.setName("b");
			b.start();
		}
		catch(InterruptedException e)
		{
			e.printStackTrace();
		}

	}

}
